package com.example.module_motocircle.ui.post.detail

import com.example.lib_net.BaseResponse
import com.example.module_motocircle.http.MotorCircleApi
import com.example.module_motocircle.http.MotorCircleNetModule
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
import javax.inject.Inject

class PostDetailRepository  @Inject constructor(){
    @Inject
    @MotorCircleNetModule.CommonMainApi
    lateinit var motorCircleApi: MotorCircleApi

//    fun postDetail() = flow {
//        emit(motorCircleApi.PostDetail())
//    }.flowOn(Dispatchers.IO)





    fun getPostDetail() = flow {
        //val baseResponse = BaseResponse<PostItem>(code = 200, data = PostItem("haha","haha"), msg = "")
        val baseResponse = motorCircleApi.PostDetail()
        emit(baseResponse)
    }.flowOn(Dispatchers.IO)

    fun getAfterSale() = flow{

        val list = mutableListOf<AfterSalePageItem>()
        for (i in 0..10) {
            list.add(AfterSalePageItem(aftersaleResult = "haha", aftersaleStatus = "haha"))
        }
        val baseResponse = BaseResponse<List<AfterSalePageItem>>(code = 200, data = list, msg = "")
        emit(baseResponse)
    }.flowOn(Dispatchers.IO)

    fun queryPostCommentsByPage( pageNum: Int, pageSize: Int = 10) = flow {
        emit(motorCircleApi.queryPostCommentsByPage(pageNum, pageSize))
    }
//    fun getComments() = flow{
//        val list = mutableListOf<CommentItem>()
//        list.add(CommentItem(name = "haha", title = "haha",isFirstLevel = true))
//        list.add(CommentItem(name = "haha", title = "haha",isFirstLevel = true))
//        list.add(CommentItem(name = "haha", title = "haha",isFirstLevel = false))
//        list.add(CommentItem(name = "haha", title = "haha",isFirstLevel = false))
//        list.add(CommentItem(name = "haha", title = "haha",isFirstLevel = true))
//        list.add(CommentItem(name = "haha", title = "haha",isFirstLevel = true))
//        list.add(CommentItem(name = "haha", title = "haha",isFirstLevel = true))
//        val baseResponse = BaseResponse<List<CommentItem>>(code = 200, data = list, msg = "")
//        emit(baseResponse)
//    }.flowOn(Dispatchers.IO)


}

data class PostItem(
    private val name:String = "",
    private val title:String = ""
)
data class CommentItem(
    val isFirstLevel:Boolean = false,
    private val name:String = "",
    private val title:String = ""
)

data class AfterSalePageItem(
    val aftersaleResult: String? = null,
    val aftersaleStatus: String? = null,
    val createBy: String? = null,
    val createName: String? = null,
    val createTime: String? = null,
    val delFlag: Boolean? = null,
    val planId: String? = null,
    val postsId: String? = null,
    val updateBy: String? = null,
    val updateName: String? = null,
    val updateTime: String? = null
) {
    fun requireTitle(): String {
        return when (aftersaleStatus) {
            "0" -> "未处理"
            "1" -> "处理中"
            "2" -> "已处理"
            else -> "--"
        }
    }
}